package valleyOfDemon;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * foreword/include请求转发
 */
@WebServlet("/ServletDemo06")
public class ServletDemo06 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        System.out.println("ServletDemo06:" + name);
        String age = req.getParameter("age");
        System.out.println("ServletDemo06:" + age);
        String[] wives = req.getParameterValues("wife");
        for (String wife : wives) {
            System.out.println("ServletDemo06:" + wife);
        }
        //可以在转发的类里使用响应对象
        //使用include后这个响应对象就无法使用了
        //resp.getWriter().write("done!");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
